<?php

class User_Backend_Security_Edit extends Kernel_Action_Form_Simple
{
    
    /**
    * Backend user role.
    * 
    * @var integer
    */
    public $role;
    
    /**
     * Таблица, в которой хранится редактируемый элемент.
     *
     * @var string
     */
    protected $_table = 'system_admin';
    
    /**
     * Initialize form elements. 
     *
     */
    protected function _initElements()
    {
        parent::_initElements();
        
        
        $this->_setElementParam('name', 'caption', __('USER_NAME'));
        if ($this->id == Security_Session::getSubjectId(Security_Subject::ADMIN)) {
            // do not allow to change permissions user itself
            $this->_setElementParam('role', 'type', 'hidden');
        } else {
            $this->_setElementParam('role', array(
                'type' => 'list', 
                'values' => __array(Backend_Utils_User::getRoles()), 
                'value' => Application::getRequest()->get(User_Backend_Security::FILTER_NAME), 
                ));
        }
        $this->_setElementParam('subject_id', 'type', 'hidden');
        $this->_setAsRequired('name');
    }
    
    protected function _done() 
    {
        $this->redirect_url .= sprintf('&%s=%d', 
            User_Backend_Security::FILTER_NAME, $this->_getValue('role'));
        
        parent::_done();
    }
    
}
